#include "SemanticNodeBlockSplit.h"

#include "main2.h"

/**
 *  @fn	SemanticNodeBlockSplit::SemanticNodeBlockSplit(const SyntaxTreeNode *splitNodeParent,
 *  	SemanticNode *parent)
 * 
 *  @brief	Constructor. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	splitNodeParent	If non-null, the split node parent.
 *  @param	parent			If non-null, the parent.
 */
SemanticNodeBlockSplit::SemanticNodeBlockSplit(const SyntaxTreeNode *splitNodeParent, SemanticNode *parent) : SemanticNode(parent), LabeledNode(splitNodeParent->Nodes->GetData(0)) {
	const SyntaxTreeNode *theNode = splitNodeParent->Nodes->GetData(1)->Nodes->GetData(0);
	into = (theNode->Nodes->GetData(1)->Nodes->GetCount() > 0);
	sendTo = (theNode->Nodes->GetData(2)->Nodes->GetCount() > 0);
	if (theNode->Nodes->GetData(2)->Production == Gr_SendTo__send_to_Name)
		sendToName = flattenNamePeriodAdd(*theNode->Nodes->GetData(2)->Nodes->GetData(2));
}
/**
 *  @fn	void SemanticNodeBlockSplit::setIntoExpression(SemanticNodeExpression *into)
 * 
 *  @brief	Sets an into expression. 
 * 
 *  @author	Nikola Novak
 *  @date	8/20/2009
 * 
 *  @param	into	If non-null, the into.
 */
void SemanticNodeBlockSplit::setIntoExpression(SemanticNodeExpression *into) {
	intoExpression = into;
}
/**
 *  @fn	bool SemanticNodeBlockSplit::hasInto(void)
 * 
 *  @brief	Query if this object has into. 
 * 
 *  @author	Nikola Novak
 *  @date	8/20/2009
 * 
 *  @return	true if into, false if not.
 */
bool SemanticNodeBlockSplit::hasInto(void) {
	return into;
}
/**
 *  @fn	bool SemanticNodeBlockSplit::hasSendTo(void)
 * 
 *  @brief	Query if this object has send to. 
 * 
 *  @author	Nikola Novak
 *  @date	8/20/2009
 * 
 *  @return	true if send to, false if not.
 */
bool SemanticNodeBlockSplit::hasSendTo(void) {
	return sendTo;
}
/**
 *  @fn	std::string SemanticNodeBlockSplit::toDebugString(int tab)
 * 
 *  @brief	Converts a tab to a debug string. 
 * 
 *  @author	Nikola Novak
 *  @date	6/25/2009
 * 
 *  @param	tab	The tab.
 * 
 *  @return	This object as a std::string.
 */
std::string SemanticNodeBlockSplit::toDebugString(int tab) {
	std::ostringstream res;
	for (int i = 0; i < tab; i++)	res << DEBUG_STRING_RAZMAK;
	res << getLabelsDebugString() << ": split ";
	if (!into) res << "into 2 ";
	else {
		res << "into " << std::endl << ((SemanticNode *)intoExpression)->toDebugString(tab + 1);
		for (int i = 0; i < tab; i++)	res << DEBUG_STRING_RAZMAK;
	}
	if (!sendTo) res << "and resume all with next block" << std::endl;
	else res << "send to " << sendToName << std::endl;
	return res.str();
}
